﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using space_matters.Utilities;

namespace space_matters
{
    class Element : Matter
    {
        #region Type Definitions

        public enum Type
        {
            Hydrogen,
            Iron,
            Carbon,
            Oxygen,
        }

        public Type type { get; set; }

        #endregion

        public TimeSpan Inactive;

        #region Constructors

        public Element(Color color, double mass, double radius, Vector2 position, Type type)
            : this(color, mass, radius, position, Vector2.Zero)
        {
            Texture = Assets.Get<Texture2D>("Cloud");
            Animation = new Animation(62, 0.06, 33, 34, 12, 6, 0, 0);
        }

        public Element(Color color, double mass, double radius, Vector2 position, Vector2 velocity, float maxVelocity = float.PositiveInfinity, Type type = Type.Hydrogen, bool scatter = false) 
            : base(color, mass, radius, position, velocity, maxVelocity)
        {
            this.type = type;
            Texture = Assets.Get<Texture2D>("Cloud");
            Animation = new Animation(62, 0.06, 33, 34, 12, 6, 0, 0);

            if (scatter)
            {
                Inactive = TimeSpan.FromSeconds(1.5);
            }
        }

        #endregion

        public override void Update(GameTime time)
        {
            if (Inactive > TimeSpan.Zero)
                Inactive -= time.ElapsedGameTime;

            if (Radius >= 8)
            {
                if (type == Type.Hydrogen) Color = Color.Yellow;
                else if (type == Type.Oxygen) Color = Color.SkyBlue;
                else if (type == Type.Carbon) Color = Color.ForestGreen;
                else Color = Color.DarkRed;
            }

            base.Update(time);
        }
    }
}
